namespace SmartSoft.Lists
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Stimulsoft.Report;
    using Stimulsoft.Report.Components;
    using System.Data;

    public class FormDmTsGEditor : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnDelete;
        private BtnControl btnSave;
        private IContainer components;
        private GBoxControl gBoxControl1;
        private object ii_MasterKey;
        private LabelControl lblMa_TGTS;
        private LabelControl lblNgay_Giam;
        private LabelControl lblSo_Ct_G;
        private DmTsDataAccess oMethod = new DmTsDataAccess();
        private TextSearch txtMa_TGTS;
        private TextDate txtNgay_Giam;
        private TextControl txtSo_Ct_G;
        private Button CmdPrint;
        private TextControl txtTen_TGTS;

        public FormDmTsGEditor()
        {
            this.InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.oMethod.TaiSanG_Delete(this.MasterKey) != 1)
            {
                MessageBox.Show("Không thể xóa được!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                base.Close();
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            this.OnSave();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDmTsGEditor));
            this.txtNgay_Giam = new SmartSoft.Controls.TextDate();
            this.lblNgay_Giam = new SmartSoft.Controls.LabelControl();
            this.btnCancel = new SmartSoft.Controls.BtnControl();
            this.btnDelete = new SmartSoft.Controls.BtnControl();
            this.gBoxControl1 = new SmartSoft.Controls.GBoxControl();
            this.txtTen_TGTS = new SmartSoft.Controls.TextControl();
            this.txtMa_TGTS = new SmartSoft.Controls.TextSearch();
            this.lblMa_TGTS = new SmartSoft.Controls.LabelControl();
            this.lblSo_Ct_G = new SmartSoft.Controls.LabelControl();
            this.txtSo_Ct_G = new SmartSoft.Controls.TextControl();
            this.btnSave = new SmartSoft.Controls.BtnControl();
            this.CmdPrint = new System.Windows.Forms.Button();
            this.gBoxControl1.SuspendLayout();
            this.SuspendLayout();
            // 
            // txtNgay_Giam
            // 
            this.txtNgay_Giam.DateTimeFormat = SmartSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Giam.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Giam.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Giam.Location = new System.Drawing.Point(79, 16);
            this.txtNgay_Giam.Mask = "00/00/0000";
            this.txtNgay_Giam.Name = "txtNgay_Giam";
            this.txtNgay_Giam.OldValue = null;
            this.txtNgay_Giam.Size = new System.Drawing.Size(78, 20);
            this.txtNgay_Giam.TabIndex = 0;
            this.txtNgay_Giam.Value = ((object)(resources.GetObject("txtNgay_Giam.Value")));
            // 
            // lblNgay_Giam
            // 
            this.lblNgay_Giam.AutoSize = true;
            this.lblNgay_Giam.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNgay_Giam.Location = new System.Drawing.Point(6, 19);
            this.lblNgay_Giam.Name = "lblNgay_Giam";
            this.lblNgay_Giam.Size = new System.Drawing.Size(57, 14);
            this.lblNgay_Giam.TabIndex = 4;
            this.lblNgay_Giam.Text = "Ngày giảm";
            // 
            // btnCancel
            // 
            this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnCancel.Location = new System.Drawing.Point(277, 116);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(79, 23);
            this.btnCancel.TabIndex = 3;
            this.btnCancel.Text = "&Quay ra";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // btnDelete
            // 
            this.btnDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnDelete.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnDelete.Location = new System.Drawing.Point(100, 116);
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new System.Drawing.Size(81, 23);
            this.btnDelete.TabIndex = 1;
            this.btnDelete.Text = "&Xóa";
            this.btnDelete.UseVisualStyleBackColor = true;
            this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
            // 
            // gBoxControl1
            // 
            this.gBoxControl1.Controls.Add(this.txtTen_TGTS);
            this.gBoxControl1.Controls.Add(this.txtMa_TGTS);
            this.gBoxControl1.Controls.Add(this.lblMa_TGTS);
            this.gBoxControl1.Controls.Add(this.lblSo_Ct_G);
            this.gBoxControl1.Controls.Add(this.txtSo_Ct_G);
            this.gBoxControl1.Controls.Add(this.txtNgay_Giam);
            this.gBoxControl1.Controls.Add(this.lblNgay_Giam);
            this.gBoxControl1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.gBoxControl1.Location = new System.Drawing.Point(12, 12);
            this.gBoxControl1.Name = "gBoxControl1";
            this.gBoxControl1.Size = new System.Drawing.Size(344, 89);
            this.gBoxControl1.TabIndex = 0;
            this.gBoxControl1.TabStop = false;
            // 
            // txtTen_TGTS
            // 
            this.txtTen_TGTS.BackColor = System.Drawing.SystemColors.Control;
            this.txtTen_TGTS.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_TGTS.CheckTextSearched = false;
            this.txtTen_TGTS.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_TGTS.Enabled = false;
            this.txtTen_TGTS.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_TGTS.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_TGTS.Location = new System.Drawing.Point(163, 61);
            this.txtTen_TGTS.Name = "txtTen_TGTS";
            this.txtTen_TGTS.OldValue = null;
            this.txtTen_TGTS.Size = new System.Drawing.Size(175, 13);
            this.txtTen_TGTS.TabIndex = 3;
            this.txtTen_TGTS.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtTen_TGTS.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_TGTS.Value = ((object)(resources.GetObject("txtTen_TGTS.Value")));
            // 
            // txtMa_TGTS
            // 
            this.txtMa_TGTS.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_TGTS.CheckTextSearched = false;
            this.txtMa_TGTS.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_TGTS.EmptyIsValid = true;
            this.txtMa_TGTS.FieldDisplay = "Ten_TGTS";
            this.txtMa_TGTS.FirstFilter = "Loai_TGTS = \'G\'";
            this.txtMa_TGTS.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_TGTS.FoundIsValid = true;
            this.txtMa_TGTS.Location = new System.Drawing.Point(79, 58);
            this.txtMa_TGTS.MaxLength = 32;
            this.txtMa_TGTS.Name = "txtMa_TGTS";
            this.txtMa_TGTS.OldValue = null;
            this.txtMa_TGTS.Size = new System.Drawing.Size(78, 20);
            this.txtMa_TGTS.TabIndex = 2;
            this.txtMa_TGTS.TableName = "DMTGTS";
            this.txtMa_TGTS.TextDisplay = this.txtTen_TGTS;
            this.txtMa_TGTS.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_TGTS.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_TGTS.Value = ((object)(resources.GetObject("txtMa_TGTS.Value")));
            // 
            // lblMa_TGTS
            // 
            this.lblMa_TGTS.AutoSize = true;
            this.lblMa_TGTS.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_TGTS.Location = new System.Drawing.Point(6, 61);
            this.lblMa_TGTS.Name = "lblMa_TGTS";
            this.lblMa_TGTS.Size = new System.Drawing.Size(59, 14);
            this.lblMa_TGTS.TabIndex = 14;
            this.lblMa_TGTS.Text = "Lý do giảm";
            // 
            // lblSo_Ct_G
            // 
            this.lblSo_Ct_G.AutoSize = true;
            this.lblSo_Ct_G.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblSo_Ct_G.Location = new System.Drawing.Point(6, 40);
            this.lblSo_Ct_G.Name = "lblSo_Ct_G";
            this.lblSo_Ct_G.Size = new System.Drawing.Size(67, 14);
            this.lblSo_Ct_G.TabIndex = 8;
            this.lblSo_Ct_G.Text = "Chứng từ số";
            // 
            // txtSo_Ct_G
            // 
            this.txtSo_Ct_G.CheckTextSearched = false;
            this.txtSo_Ct_G.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtSo_Ct_G.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSo_Ct_G.Location = new System.Drawing.Point(79, 37);
            this.txtSo_Ct_G.MaxLength = 20;
            this.txtSo_Ct_G.Name = "txtSo_Ct_G";
            this.txtSo_Ct_G.OldValue = null;
            this.txtSo_Ct_G.Size = new System.Drawing.Size(78, 20);
            this.txtSo_Ct_G.TabIndex = 1;
            this.txtSo_Ct_G.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemUnit;
            this.txtSo_Ct_G.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtSo_Ct_G.Value = ((object)(resources.GetObject("txtSo_Ct_G.Value")));
            // 
            // btnSave
            // 
            this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnSave.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnSave.Location = new System.Drawing.Point(12, 116);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(82, 23);
            this.btnSave.TabIndex = 0;
            this.btnSave.Text = "&Lưu";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // CmdPrint
            // 
            this.CmdPrint.Location = new System.Drawing.Point(187, 116);
            this.CmdPrint.Name = "CmdPrint";
            this.CmdPrint.Size = new System.Drawing.Size(86, 23);
            this.CmdPrint.TabIndex = 2;
            this.CmdPrint.Text = "&In biên bản TL";
            this.CmdPrint.UseVisualStyleBackColor = true;
            this.CmdPrint.Click += new System.EventHandler(this.CmdPrint_Click);
            // 
            // FormDmTsGEditor
            // 
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(368, 151);
            this.Controls.Add(this.CmdPrint);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnSave);
            this.Controls.Add(this.btnDelete);
            this.Controls.Add(this.gBoxControl1);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormDmTsGEditor";
            this.Text = "Ghi giảm tài sản";
            this.gBoxControl1.ResumeLayout(false);
            this.gBoxControl1.PerformLayout();
            this.ResumeLayout(false);

        }

        private void OnSave()
        {
            if (this.txtNgay_Giam.Value.Equals(DBNull.Value))
            {
                MessageBox.Show("Chưa nhập ngày giảm tài sản!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (this.txtMa_TGTS.Value.Equals(DBNull.Value))
            {
                MessageBox.Show("Chưa nhập lý do giảm tài sản!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (this.oMethod.TaiSanG_Save(this.MasterKey, this.txtNgay_Giam.Value, this.txtSo_Ct_G.Value, this.txtMa_TGTS.Value) != 1)
            {
                MessageBox.Show("Không lưu được dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                base.Close();
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.OnSave();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        public object MasterKey
        {
            get
            {
                return this.ii_MasterKey;
            }
            set
            {
                this.ii_MasterKey = value;
                object obj2 = DateTime.Now;
                object obj3 = SDBNull.Value;
                object obj4 = SDBNull.Value;
                object obj5 = SDBNull.Value;
                this.oMethod.TaiSanG_Get(this.ii_MasterKey, ref obj2, ref obj3, ref obj4, ref obj5);
                this.txtNgay_Giam.Value = obj2;
                this.txtSo_Ct_G.Value = obj3;
                this.txtMa_TGTS.Value = obj4;
                this.txtTen_TGTS.Value = obj5;
            }
        }

        private void CmdPrint_Click(object sender, EventArgs e)
        {
           
            StiReport report = new StiReport();
            DataTable datatable1 = this.oMethod.GetMasterDataRow(this.ii_MasterKey).Table.Copy();
            report.RegData(datatable1);
 
            report.Load(Application.StartupPath + "\\ReportFiles\\BS03TS.mrt");
            report.Compile();
            report["Ngay_Ct"] = "Ngày: " + ((DateTime)this.txtNgay_Giam.Value).ToString("dd/MM/yyyy");
            report["So_Ct"] = this.txtSo_Ct_G.Value.ToString();
            report.Show();
        }
    }
}

